package com.foton.designmodel.strategy;

import com.foton.util.SpringFactoryUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
@ConfigurationProperties(prefix = "strategy")
public class StrategyFactory  {

//    private ApplicationContext act;


    //1:配置文件进行配置，实例和会员等级的映射
    @Setter
    private Map<Integer, String> strategyMap;

    //2:根据会员等级进行从spring容器中进行获取
    public VipMoney getExecuteInstance(Integer vipLevel) {
        return SpringFactoryUtil.getBean(strategyMap.get(vipLevel), VipMoney.class);
    }


//    /**
//     * 注入容器
//     *
//     * @param applicationContext
//     * @throws BeansException
//     */
//    @Override
//    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//        act = applicationContext;
//    }

}
